import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * @Author:Star
 * @Date:Created in 14:10 2019/5/12
 * @Description:
 */
public class Customer {
    private KFCFactoryImpl kfcFactory;

    public Customer(KFCFactoryImpl kfcFactory) {
        this.kfcFactory = kfcFactory;
    }

    private ArrayList<String> billList = new ArrayList<>();

    //打印小票文件
    public void showBill() throws IOException {
        BufferedWriter bw = new BufferedWriter(new FileWriter("D://text.txt", true));
        bw.write("*****************************************************\r\n");
        bw.write("             **欢迎光临荔枝堡**             \r\n");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        bw.write("订餐时间："+df.format(new Date())+"\r\n");// new Date()为获取当前系统时间
        bw.write("名称    \t\t单价\t数量\t价格\r\n");
        for(String str:billList){
            bw.write(str);
            bw.newLine();
            bw.flush();
        }
    }

    //显示订单
    public void outBill(){
        for(String str:billList){
            System.out.println(str);
        }
    }

    //获得汉堡
    public float getHamburg(int choose,int num){
        Hamburg hamburg;
        hamburg = kfcFactory.createHamburg(choose,num);
        System.out.print(hamburg.printMessage());
        billList.add(hamburg.printMessage());
        return hamburg.totalPrice();
    }

    //获得冰淇淋
    public float getIceCream(int choose,int num){
        IceCream icecream;
        icecream = kfcFactory.createIceCream(choose,num);
        System.out.print(icecream.printMessage());
        billList.add(icecream.printMessage());
        return icecream.totalPrice();
    }

    //获得饮料
    public float getBeverage(int choose,int num){
        Beverage beverage;
        beverage = kfcFactory.createBeverage(choose,num);
        System.out.print(beverage.printMessage());
        billList.add(beverage.printMessage());
        return beverage.totalPrice();
    }

    //获得炸鸡
    public float getChicken(int choose,int num){
        Chicken chicken;
        chicken = kfcFactory.createChicken(choose,num);
        System.out.print(chicken.printMessage());
        billList.add(chicken.printMessage());
        return chicken.totalPrice();
    }

    //获得套餐
    public float getSetMeal(int choose,int num){
        Hamburg hamburg;
        Chicken chicken;
        IceCream iceCream;
        Beverage beverage;
        float money;
        if(1 == choose){
            hamburg = kfcFactory.createHamburg(3,1);
            beverage = kfcFactory.createBeverage(2,1);
            chicken = kfcFactory.createChicken(1,1);
            billList.add(hamburg.printMessage());
            billList.add(beverage.printMessage());
            billList.add(chicken.printMessage());
            money = Math.round(0.9*(hamburg.totalPrice()+beverage.totalPrice()+chicken.totalPrice())*num);
            return money;
        }else if(2 == choose){
            hamburg = kfcFactory.createHamburg(2,3);
            beverage = kfcFactory.createBeverage(2,3);
            chicken = kfcFactory.createChicken(2,2);
            iceCream = kfcFactory.createIceCream(1,1);
            billList.add(hamburg.printMessage());
            billList.add(beverage.printMessage());
            billList.add(chicken.printMessage());
            billList.add(iceCream.printMessage());
            money = Math.round(0.9*(hamburg.totalPrice()+beverage.totalPrice()+chicken.totalPrice()+iceCream.totalPrice())*num);
            return money;
        }else if(3 == choose){
            hamburg = kfcFactory.createHamburg(1,2);
            iceCream = kfcFactory.createIceCream(3,2);
            beverage = kfcFactory.createBeverage(2,2);
            chicken = kfcFactory.createChicken(1,1);
            billList.add(hamburg.printMessage());
            billList.add(beverage.printMessage());
            billList.add(chicken.printMessage());
            billList.add(iceCream.printMessage());
            money = Math.round(0.9*(hamburg.totalPrice()+beverage.totalPrice()+chicken.totalPrice()+iceCream.totalPrice())*num);
            return money;
        }else{
            System.out.println("没有该套餐！！！");
            return 0;
        }
    }
}